// https://soj.turingedu.cn/problem/50302/
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <deque>
using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
int rad(); // read int
const int max_size = 5 + 2e5;
const int maxn = 5 + 2e5;

int n, m;
int a[maxn];
int f[maxn]; // f[i] 选择 i 的最小代价
// f[i] = min(f[i - j]) + a[i], j->[1, m]

struct Node {
    int val, pos;
};

deque<Node> qe;

void push_inc(int val, int pos) {
    while (!qe.empty() && qe.back().val > val)
        qe.pop_back();
    while (!qe.empty() && pos - qe.front().pos >= m)
        qe.pop_front();
    qe.push_back({val, pos});
}

int main() {
    n = rad(), m = rad();
    rf(i, n) a[i] = rad();
    qe.push_back({0, 0});
    for (int i = 1; i <= n; ++i) {
        f[i] = qe.front().val + a[i];
        push_inc(f[i], i);
    }
    printf("%d\n", qe.front().val);
}

int rad() {
    int back = 0, ch = 0, neg = 0;
    for (; ch < '0' || ch > '9'; ch = getchar())
        neg = ch == '-';
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        back = (back << 1) + (back << 3) + (ch & 0xf);
    return (back ^ -neg) + neg;
}